<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation
include_once("MerchantClass.php");						//--> Merchant
require_once("controlHeader.php");					//--> system control header
require_once("../tools/fckeditor/fckeditor.php") ;

$objOperate 	= new Operation($sessionImpl->getLanguage());			//--> Operation
$objMerchant	= new MerchantClass(DB_TAG_COUPON, $uid);				//--> Merchant

$error_message 	= '';


$type 		= '1';
$status		= '1';
$authorized	= '1';

$name		= '';
$descript 	= '';


$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(isset($_POST['Submit'])){
	$name 				= $_POST['name'];
	$displayURL			= $_POST['displayURL'];
	$sitemapPriority 	= addslashes($_POST['sitemapPriority']);
	$rating 			= $_POST['rating'];
	$headline 			= addslashes($_POST['headline']);
	$CSPhone 			= $_POST['CSPhone'];
	$CSEmail 			= $_POST['CSEmail'];
	$url 				= $_POST['url'];
	$descript 			= addslashes($_POST['descript']);
	$alias 				= addslashes($_POST['alias']);
	$address 			= addslashes($_POST['address']);
	
	$type 				= $_POST['type'];
	$authorized 		= $_POST['authorized'];
	
	$status 			= $_POST['status'];
	
	if(empty($name)){
		$error_message = 'Merchant name should\'t be empty.';
	}else if($objMerchant->IsExistName($name)){
		$error_message = 'Merchant name be existed.';
	}else{
		$isReturn = $objMerchant->add($arrOperate, $type, $name, $descript, $authorized, $CSPhone, $CSEmail, $url, $rating, $displayURL, $sitemapPriority, $status, $headline, $alias, $address);
		if($isReturn){
			$error_message = 'add successfully.';
			
		}else 
			$error_message = 'add failure.';
	}
}

/*----- load FCKEditor -----*/
$oFCKeditor = new FCKeditor('descript') ;

//$oFCKeditor->Height		= 300;
$oFCKeditor->BasePath		= FCKeditor_BASE_PATH;

$oFCKeditor->Value = $descript;

$fckHtml = $oFCKeditor->CreateHtml() ;

$arrAuthorized 	= array('1' => 'YES', '0' => 'NO');
$arrStatus 		= array('1' => 'Normal', '0' => 'Stop');
$arrType 		= array("1" =>"CPC", "2" => "CPA");
 
/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('error_message', $error_message);
$smarty->assign('backurl',$backurl);

$smarty->assign('headline', $headline);
$smarty->assign('name', $name);
$smarty->assign('displayURL', $displayURL);
$smarty->assign('sitemapPriority', $sitemapPriority);
$smarty->assign('rating', $rating);
$smarty->assign('headline', $headline);

$smarty->assign('CSPhone', $CSPhone);
$smarty->assign('CSEmail', $CSEmail);
$smarty->assign('url', $url);
$smarty->assign('descript', $descript);


$smarty->assign('arrType', $arrType);
$smarty->assign('type', $type);

$smarty->assign('arrAuthorized', $arrAuthorized);
$smarty->assign('authorized', $authorized);

$smarty->assign('arrStatus', $arrStatus);
$smarty->assign('status', $status);

$smarty->assign("fckHtml", $fckHtml);

$smarty->display('listMerchant_Add.htm');
?>
